import 'package:flutter/material.dart';
import 'package:flutter_app/controller/MineControl.dart';
import 'package:flutter_app/controller/SplashControl.dart';
import 'package:flutter_app/mine/my_info.dart';
import 'package:flutter_app/mine/trade_record_page.dart';
import 'package:get/get.dart';
class MinePage extends StatefulWidget {
  int personType;
  MinePage(int personType){
    this.personType=personType;
  }
  @override
  State<StatefulWidget> createState() {
    return new MinePageState(personType);
  }
}

class MinePageState extends State<MinePage>{
  final SpalshController control = SpalshController.to;

  MinePageState(int personType){
    control.personType.value=personType;
  }

  @override
  Widget build(BuildContext context) {

    return Container(
        alignment: Alignment.center,
        height: 800,
        color: Color(0xffF4F4F4),
       child:Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Obx(()=>Text("个人中心>${control.getTitle()}",style: TextStyle(color: Color(0xff2E2F33)),)),
                SizedBox(height: 10,),
                Row(
                  children: [
                    Column(
                      children: control.maps.map((e) => Obx(()=>Container(
                        padding: EdgeInsets.only(bottom: 20),
                        child: control.maps[control.personType.value-1]==e?buildSelect(e):buildNotSelect(e),
                      ))).toList(),
                    )
                  ],
                )
              ],
            ),
            Container(
              width: 900,
              height: 700,
              color: Colors.white,
              margin: EdgeInsets.only(top: 30),
              child: Obx(()=>pageView()),
            )
          ],
       )

    );
  }

  Widget pageView(){
    if(control.personType.value==1){
      return MyInfoPage();
    }else if(control.personType.value==2){
      return TradeRecordPage();
    }else{
      return MyInfoPage();
    }
  }

  Widget buildSelect(String e){
    return Container(
      width: 100,
      child: InkWell(
        onTap: (){
          if(e=="个人中心") control.personType.value=1;
          else if(e=="交易记录") control.personType.value=2;
          else if(e=="账单管理") control.personType.value=3;
          else if(e=="待核销金额") control.personType.value=4;
          else if(e=="优惠券") control.personType.value=5;
        },
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              width: 2,
              height: 15,
              color: Color(0xff1A4677),
            ),
            SizedBox(width: 3,),
            Text(
              e,
              style: TextStyle(color: Color(0xff1A4677)),
            )
          ],
        ),
      ),
    );
  }

  Widget buildNotSelect(String e){
    return Container(
      width: 100,
      child: InkWell(
        onTap: (){
          if(e=="个人中心") control.personType.value=1;
          else if(e=="交易记录") control.personType.value=2;
          else if(e=="账单管理") control.personType.value=3;
          else if(e=="待核销金额") control.personType.value=4;
          else if(e=="优惠券") control.personType.value=5;
        },
        child:  Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              width: 2,
              height: 15,
            ),
            SizedBox(width: 3,),
            Text(
              e,
              style: TextStyle(color: Color(0xff2E2F33)),
            )
          ],
        ),
      ),
    );
  }
}